| Class | SimplyPresentable::ActiveRecordFormPresenter |
| In: |
vendor/plugins/simply_presentable/lib/simply_presentable/presenter/active_record_form.rb
|
| Parent: | SimplyPresentable::ActiveRecordPresenter |
Will call ActionView::Helpers::FormHelper.fields_for with the options passed as arguments. The name for the fields is determined by the name of the presented class:
present(FooBar.new).fields
will prefix the fields with foo_bar
# File vendor/plugins/simply_presentable/lib/simply_presentable/presenter/active_record_form.rb, line 8
8: def fields(options = {}, &proc)
9: @renderer.fields_for record_name, @presenter_proxy, options, &proc
10: end
Will call form_for with the options needed to create a form for the presented object:
present(Foo.new).form do |f|
f.text_field :bar
end
is equivalent to
form_for(:url => 'http://example.com/foos', :html => {:method => 'post', :id => 'new_foo', :class => 'new_foo'}) do |f|
f.text_field :bar
end
present(Foo.find(1)).form_for do |f|
f.text_field :bar
end
is equivalent to
form_for(:url => 'http://example.com/foos/1', :html => {:method => 'put', :id => 'foo_1', :class => 'foo'}) do |f|
f.text_field :bar
end
Options:
| :url_options: | Options to pass to url method called on ActiveRecordUrlPresenter |
You can also override any of the options selected by default:
present(Foo.new).form_for(:html => {:id => 'bar'}) do |f| ...
# File vendor/plugins/simply_presentable/lib/simply_presentable/presenter/active_record_form.rb, line 35
35: def form(options = {}, &proc)
36: @renderer.form_for record_name, @presenter_proxy, form_options_from(options), &proc
37: end